package com.wanxi.servlet;

import com.wanxi.dao.BrandDao;
import com.wanxi.model.Brand;
import com.wanxi.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/findAll")
public class FindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1.乱码处理
        resp.setCharacterEncoding("UTF-8");
        req.setCharacterEncoding("UTF-8");
        //        2.得到前端的值
        //        3.将数据封装成对象
        Brand brand=new Brand();
        //        4.要先处理逻辑关系
        BrandService brandService = new BrandService();
        List<Brand> list = brandService.findAll(brand);


//        list = new BrandDao().getList(brand);
//        数据存入req里面
        req.setAttribute("list", list);
//        数据共享，将数据转发到jsp页面
        req.getRequestDispatcher("/findAll.jsp").forward(req, resp);
    }
}
